<template>
  <div class="page-container">
    <SearchPanel @change="handleSearchPanelChange">
      <el-form
        ref="queryForm"
        class="query-more-form"
        size="mini"
        label-width="100px"
        :model="query"
      >
        <el-row :gutter="21">
          <el-col :span="5">
            <el-form-item label="姓名">
              <el-input
                v-model="query.name"
                class="search-ipt"
                placeholder="请输入姓名"
                maxlength="255"
              />
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="时间区间">
              <el-date-picker
                v-model="query.startTime"
                type="datetimerange"
                size="mini"
                range-separator="-"
                start-placeholder="开始"
                end-placeholder="结束"
                value-format="yyyy-MM-dd"
                format="yyyy-MM-dd"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="4" class="btn-col">
            <el-button size="mini" class="search-btn" @click="select"
              >查询</el-button
            >
          </el-col>
        </el-row>
      </el-form>
    </SearchPanel>
    <div class="table-container">
      <div class="table-tools-panel table-flex-row">
        <div class="table-btns-left">
          <el-button class="flush-btn" icon="el-icon-refresh" @click="refresh"
            >刷新</el-button
          >
          <!-- <input type="button" value="toggle" v-on:click="toggle()" /> -->
          <el-radio-group v-model="radio" @change="getValue()" size="mini">
            <el-radio-button
              v-for="(item, i) in items"
              :key="i"
              :label="i"
              :disabled="item.disabled"
              >{{ item.content }}</el-radio-button
            >
          </el-radio-group>
        </div>
        <div>
          <el-button
            class="tools-btn"
            size="mini"
            icon="el-icon-set-up"
          ></el-button>
          <el-button
            class="tools-btn"
            size="mini"
            icon="el-icon-share"
          ></el-button>
          <el-button
            class="tools-btn"
            size="mini"
            icon="el-icon-printer"
          ></el-button>
        </div>
      </div>
      <div class="table-list-panel">
        <!-- 责任分工清单0 -->
        <el-table
          v-loading="tableLoading"
          border
          size="small"
          :data="tableData0"
          :height="isShow ? 'calc(100vh - 455px)' : 'calc(100vh - 380px)'"
          style="width: 100%"
          display="none"
          v-show="showAreas0"
        >
          <el-table-column type="selection" width="45" />
          <el-table-column
            prop="number"
            label="编号"
            show-overflow-tooltip
          /><el-table-column
            prop="type"
            label="类别"
            show-overflow-tooltip
          /><el-table-column
            prop="details"
            label="具体事项"
            show-overflow-tooltip
          /><el-table-column
            prop="deptResponsibility"
            label="区（市）县部门责任"
            show-overflow-tooltip
          /><el-table-column
            prop="streetResponsibility"
            label="镇（街道）责任"
            show-overflow-tooltip
          /><el-table-column
            prop="legalBasis"
            label="法定依据"
            show-overflow-tooltip
          /><el-table-column
            prop="remarks"
            label="备注"
            show-overflow-tooltip
          />
          <el-table-column label="操作" width="90" fixed="right">
            <template slot-scope="scope">
              <el-button
                class="table-inner-btn"
                type="text"
                size="mini"
                @click.native="handDetail0(scope.row)"
                >详情</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <!-- 公共服务清单1 -->
        <el-table
          v-loading="tableLoading"
          border
          size="small"
          :data="tableData1"
          :height="isShow ? 'calc(100vh - 455px)' : 'calc(100vh - 380px)'"
          style="width: 100%"
          display="none"
          v-show="showAreas1"
        >
          <el-table-column type="selection" width="45" />
          <el-table-column
            prop="number"
            label="编号"
            show-overflow-tooltip
          /><el-table-column
            prop="category"
            label="类别"
            show-overflow-tooltip
          /><el-table-column
            prop="itemName"
            label="事项名称"
            show-overflow-tooltip
          /><el-table-column
            prop="correspondingDepartment"
            label="对应部门"
            show-overflow-tooltip
          /><el-table-column
            prop="completionTime"
            label="办结时限"
            show-overflow-tooltip
          /><el-table-column
            prop="placeProcessing"
            label="办理地点"
            show-overflow-tooltip
          />
          <el-table-column
            prop="implementationBasis"
            label="实施依据"
            show-overflow-tooltip
          /><el-table-column
            prop="remarks"
            label="备注"
            show-overflow-tooltip
          />
          <el-table-column label="操作" width="90" fixed="right">
            <template slot-scope="scope">
              <el-button
                class="table-inner-btn"
                type="text"
                size="mini"
                @click.native="handDetail1(scope.row)"
                >详情</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <!-- 职责任务清单2 -->
        <el-table
          v-loading="tableLoading"
          border
          size="small"
          :data="tableData2"
          :height="isShow ? 'calc(100vh - 455px)' : 'calc(100vh - 380px)'"
          style="width: 100%"
          display="none"
          v-show="showAreas2"
        >
          <el-table-column type="selection" width="45" />
          <el-table-column
            prop="number"
            label="编号"
            show-overflow-tooltip
          /><el-table-column
            prop="type"
            label="职能分类"
            show-overflow-tooltip
          /><el-table-column
            prop="responsibilitiesTasks"
            label="职责任务"
            show-overflow-tooltip
          /><el-table-column
            prop="details"
            label="工作事项"
            show-overflow-tooltip
          /><el-table-column
            prop="legalBasis"
            label="依据来源"
            show-overflow-tooltip
          /><el-table-column
            prop="remarks"
            label="备注"
            show-overflow-tooltip
          />
          <el-table-column label="操作" width="90" fixed="right">
            <template slot-scope="scope">
              <el-button
                class="table-inner-btn"
                type="text"
                size="mini"
                @click.native="handDetail2(scope.row)"
                >详情</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="pagination-panel">
        <Pagination
          :total="query.total"
          :page.sync="query.pageNum"
          :limit.sync="query.pageSize"
          @pagination="select"
        />
      </div>
    </div>
    <areas0Dialog
      :dialogVisible="visible0"
      :type="query.type0"
      :obj="obj"
      @closeDialog="visible0 = false"
      @refresh="refresh"
    />
    <areas1Dialog
      :dialogVisible="visible1"
      :type="query.type1"
      :obj="obj"
      @closeDialog="visible1 = false"
      @refresh="refresh"
    />
    <areas2Dialog
      :dialogVisible="visible2"
      :type="query.type2"
      :obj="obj"
      @closeDialog="visible2 = false"
      @refresh="refresh"
    />
  </div>
</template>

<script>
import SearchPanel from "@/components/SearchPanel";
import Pagination from "@/components/Pagination";
import { getAreas0 } from "@/api/system/listing";
import { getAreas1 } from "@/api/system/listing";
import { getAreas2 } from "@/api/system/listing";
import areas0Dialog from "./components/areas0Dialog";
import areas1Dialog from "./components/areas1Dialog";
import areas2Dialog from "./components/areas2Dialog";

export default {
  name: "listing",
  components: {
    SearchPanel,
    Pagination,
    areas0Dialog,
    areas1Dialog,
    areas2Dialog,
  },
  data() {
    return {
      visible0: false,
      visible1: false,
      visible2: false,
      query: {
        total: 0,
        pageNum: 1,
        pageSize: 10,
      },
      tableLoading: false,
      tableData0: [],
      tableData1: [],
      tableData2: [],
      department0: [],
      department1: [],
      department2: [],
      isShow: true,dialogType : "detail",
      obj: {},
      // 三清单选择显示
      showAreas0: true,
      showAreas1: false,
      showAreas2: false,
      radio: 0,
      items: [
        { id: 0, content: "责任分工清单", disabled: false },
        { id: 1, content: "公共服务清单", disabled: false },
        { id: 2, content: "职责任务清单", disabled: false },
      ],
    };
  },
  created() {
    this.initData();
  },
  methods: {
    handleSearchPanelChange(flag) {
      this.isShow = flag;
    },
    initData() {
      this.select();
    },
    select() {
      // 数据加载提示
      const query = JSON.parse(JSON.stringify(this.query));
      this.tableLoading = true;
      if(this.radio == 0){
        getAreas0(this.query).then((result) => {
          this.tableLoading = false;
          this.query.total = result.total;
          this.tableData0 = result.rows;
        })
        .catch(() => {
          this.tableLoading = false;
        });  
      }else if(this.radio == 1){
        getAreas1(this.query)
        .then((result) => {
          this.tableLoading = false;
          this.query.total = result.total;
          this.tableData1 = result.rows;
        })
        .catch(() => {
          this.tableLoading = false;
        });
      }else if(this.radio == 2){
         getAreas2(this.query)
        .then((result) => {
          this.tableLoading = false;
          this.query.total = result.total;
          this.tableData2 = result.rows;
        })
        .catch(() => {
          this.tableLoading = false;
        });
      }
     
    },
    // 刷新页面
    refresh() {
      this.query = {
        total: 1,
        pageNum: 1,
        pageSize: 10,
        type0: 1,
        type1: 1,
        type2: 1,
        name: "",
      };
      this.select();
    },
    // 三清单选择显示
    getValue() {
      if (this.radio == 0) {
        this.getValueClose();
        this.showAreas0 = !this.showAreas0;
        this.select();
      } else if (this.radio == 1) {
        this.getValueClose();
        this.showAreas1 = !this.showAreas1;
        this.select();
      } else if (this.radio == 2) {
        this.getValueClose();
        this.showAreas2 = !this.showAreas2;
        this.select();
      } else {
        // alert("什么操作!?");
      }
    },
    // 清除所有表格
    getValueClose() {
      this.showAreas0 = false;
      this.showAreas1 = false;
      this.showAreas2 = false;
    },
    // 3个详情
    handDetail0(row) {
        // this.dialogType = "detail";
        this.visible0 = true;
        this.obj = row;
    },handDetail1(row) {
        // this.dialogType = "detail";
        this.visible1 = true;
        this.obj = row;
    },handDetail2(row) {
        // this.dialogType = "detail";
        this.visible2 = true;
        this.obj = row;
    },
  },
};
</script>

<style lang="scss" scoped>
</style>